package top.hekun.study.core.visitor.method.simple;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

/**
 * 打印方法参数和返回值 方法
 *
 * @Author: 贺坤
 * @Date: 2023/5/10 10:08
 */
public class MyClassVisitorModifyMethodCode5 extends ClassVisitor {
    private int apiVersion;
    private String thisClassName = this.getClass().getSimpleName();

    public MyClassVisitorModifyMethodCode5(int apiVersion, ClassVisitor classVisitor) {
        super(apiVersion, classVisitor);
        this.apiVersion = apiVersion;
    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        System.out.println(thisClassName + " -- " + name + " -- " + descriptor);
        MethodVisitor visitor = super.visitMethod(access, name, descriptor, signature, exceptions);

        if (visitor != null && "test3".equals(name) && Type.getMethodDescriptor(Type.DOUBLE_TYPE,Type.INT_TYPE,Type.INT_TYPE).equals(descriptor)) {
            return new MyMethodVisitor5(apiVersion,visitor,descriptor,access);
        }
        return visitor;
    }
}
